#include "hoopoe.h"

#pragma warning(disable:4995)
#include <strsafe.h>


// here we define signatures
//

int msi_signature[] = {0xD0, 0xCF, 0x11, 0xE0, 0xA1, 0xB1, 0x1A, 0xE1, 0x00};



unsigned int gLastErrorCode = 0;

void ExitWithError(LPTSTR lpszFunction)
{
	LPVOID lpMsgBuf;
	LPVOID lpDisplayBuf;


	gLastErrorCode = GetLastError();
	//cout<<"Error Occured: Function Name: ("<<function_name<<") : Error: "<<gLastErrorCode<<endl;

	FormatMessage(
        FORMAT_MESSAGE_ALLOCATE_BUFFER | 
        FORMAT_MESSAGE_FROM_SYSTEM |
        FORMAT_MESSAGE_IGNORE_INSERTS,
        NULL,
        gLastErrorCode,
        MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
        (LPTSTR) &lpMsgBuf,
        0, NULL );
	
   lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, 
        (lstrlen((LPCTSTR)lpMsgBuf) + lstrlen((LPCTSTR)lpszFunction) + 40) * sizeof(TCHAR)); 

   StringCchPrintf((LPTSTR)lpDisplayBuf, 
        LocalSize(lpDisplayBuf) / sizeof(TCHAR),
        TEXT("%s failed with error %d: %s"), 
        lpszFunction, gLastErrorCode, lpMsgBuf); 

	printf("%s", (LPCTSTR)lpDisplayBuf); 

	ExitProcess(0);
}